package com.jp.knowledge.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jiayen.util.DisplayUtil;
import com.jp.knowledge.R;
import com.jp.knowledge.activity.BaseFragment;
import com.jp.knowledge.adapter.FoundGridAdapter;
import com.jp.knowledge.model.FoundItem;
import com.jp.knowledge.view.FoundItemView;
import com.jp.knowledge.view.WrapGridVIew;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jiayen on 16/9/28.
 */
public class FoundFragmentold extends BaseFragment {


    private TextView topName;
    private TextView topDesc;
    private View  mView;
    private WrapGridVIew  gridView;
    private Context mContext;
    private LinearLayout contentLayout;

    private  int[] imgs = new int[]{R.mipmap.faxianbaoliaoquan,R.mipmap.faxianhuati,R.mipmap.faxianguanjialaile,R.mipmap.faxianquanmingfeenxiang,
                                    R.mipmap.faxianzhishiku,R.mipmap.faxianjingpinzhuti,R.mipmap.faxianqingtiyan,R.mipmap.faxianhaofangan,R.mipmap.faxianzaiyong};

    private String[] names = new String[]{"爆料圈","话题","管家来了","全民分享","知识库","竞品主题","竞报","好方案","在用"};


    private int[] gridImgs=new int[]{R.mipmap.faxianqingwen,R.mipmap.faxiantop,R.mipmap.faxianjinengguangchang,R.mipmap.faxianchuangjiangshuo,R.mipmap.faxianjifenshangcheng,
                                        R.mipmap.faxianchanpinku,R.mipmap.faxiangongsiku,R.mipmap.faxianrenwuku,R.mipmap.faxianpingdao};
    private String[] gridNames = new String[]{"请问","Top 1000","技能广场","创将说","积分商城","产品库","公司库","人物库","频道"};
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.found_fragment_old,null);
        this.mContext=getActivity();
        init();
        return mView;
    }

    private void setFound() {
        topName.setText("发现");
        topDesc.setText("探索互联网世界");
    }
    private void init() {

        topName= (TextView) mView.findViewById(R.id.module_name);
        topDesc= (TextView) mView.findViewById(R.id.module_desc);

        gridView = (WrapGridVIew) mView.findViewById(R.id.grid);

        contentLayout = (LinearLayout) mView.findViewById(R.id.content);

        List<FoundItem> list = new ArrayList<>();
        int length = gridImgs.length;
        for (int i = 0; i < length; i++) {
            FoundItem item = new FoundItem();
            item.setResId(gridImgs[i]);
            item.setName(gridNames[i]);
            list.add(item);
        }
        FoundGridAdapter adpter = new FoundGridAdapter(mContext,list);
        gridView.setAdapter(adpter);

        int size = imgs.length;

        for (int i = 0; i < size; i++) {
            FoundItemView foundItem  = new FoundItemView(mContext);
            FoundItem item = new FoundItem();
            item.setResId(imgs[i]);
            item.setName(names[i]);
            if(i<2){
                item.setShowPhoto(true);
            }else{
                item.setShowPhoto(false);
            }
            if(i>=5){
                item.setShowDescription(false);
                item.setShowTip(false);
            }else{
                item.setShowDescription(true);
                item.setDescriton("1302次体验");
                item.setShowTip(true);
            }

            foundItem.setItem(item);
            contentLayout.addView(foundItem);

            if(i==4||i==size-1){
                contentLayout.addView(getMaxLineView());
            }else{
                contentLayout.addView(getLineView());
            }

        }

//        setFound();
    }



    private View getLineView(){
        View view = new View(mContext);
        view.setBackgroundColor(getResources().getColor(R.color.found_line_gray));
        view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,1));
        return view;
    }


    private View getMaxLineView(){
        View view = new View(mContext);
        view.setBackgroundColor(getResources().getColor(R.color.found_line_gray));
        view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, DisplayUtil.dip2px(mContext,10)));
        return view;
    }
}
